﻿using System;
using System.IO;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
using HKB.Common;
using HKB.Web;
using HKB.Web.Admin;
using HKB.Web.DataHelper;
using HKB.Data;

public partial class Admin_Admin_ManageAdZone : Admin, IRequiresSessionState
{
    protected DefaultProfile profile
    {
        get
        {
            return (DefaultProfile)this.Context.Profile;
        }
    }
    protected global_asax applicationInstance
    {
        get
        {
            return (global_asax)this.Context.ApplicationInstance;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        base.admin.CheckAdminPower(12);
        if (base.Request["ZoneIntro"] != null)
        {
            this.ZoneType.SelectedValue = base.Request["ZoneIntro"];
        }
        if (base.Request["ZoneName"] != null)
        {
            this.ZoneName.Text = base.Request["ZoneName"];
        }
        if (!base.IsPostBack)
        {
            if (!base.admin.CheckAdminPower(14))
            {
                this.Button3.Enabled = false;
            }
        }
        if (base.Request.QueryString["Zonetype"] != null)
        {
            this.ZoneType.SelectedValue = base.Request.QueryString["Zonetype"];
        }
        else
        {
            this.ZoneType.SelectedIndex = 0;
        }
    }
    public void DeleteJS(int AdZoneID)
    {
        AdZoneBll adZoneBll = new AdZoneBll();
        string text = adZoneBll.GetSingeAdZone(AdZoneID).Rows[0]["ZoneJSName"].ToString();
        text = base.Server.MapPath("..") + "\\AD\\" + text;
        try
        {
            if (File.Exists(text))
            {
                File.Delete(text);
            }
        }
        catch (Exception ex)
        {
            base.Response.Write(ex.Message.ToString());
            base.Response.End();
        }
    }
    protected void GridView1_SelectedIndexChanged(object sender, CommandEventArgs e)
    {
        if (!base.admin.CheckAdminPower(14))
        {
            base.WriteLog("Delete", Language.GetAdminMsg("Log/Access", "0"), "Ads");
            base.WriteRightErrMsg();
        }
        AdZoneBll adZoneBll = new AdZoneBll();
        this.DeleteJS(int.Parse(e.CommandName.ToString()));
        adZoneBll.DelectAdZone(int.Parse(e.CommandName.ToString()));
        this.WriteErrMsg("", Language.GetAdminMsg("Common/DeleteSuccess", ""), "");
        this.GridView1.DataBind();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow gridViewRow in this.GridView1.Rows)
        {
            CheckBox checkBox = (CheckBox)gridViewRow.FindControl("CheckBox1");
            checkBox.Checked = !checkBox.Checked;
        }
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        if (!base.admin.CheckAdminPower(14))
        {
            base.WriteLog("Delete", Language.GetAdminMsg("Log/Access", "0"), "Ads");
            base.WriteRightErrMsg();
        }
        string text = "";
        foreach (GridViewRow gridViewRow in this.GridView1.Rows)
        {
            CheckBox checkBox = (CheckBox)gridViewRow.FindControl("CheckBox1");
            if (checkBox.Checked)
            {
                text = text + checkBox.Text + ",";
                this.DeleteJS(int.Parse(checkBox.Text));
            }
        }
        if (text != "")
        {
            string zoneIDArr = text.Remove(text.Length - 1);
            AdZoneBll adZoneBll = new AdZoneBll();
            adZoneBll.DeleteAdZones(zoneIDArr);
        }
        this.WriteErrMsg("", Language.GetAdminMsg("Common/DeleteSuccess", ""), "Admin_ManageAdZone.aspx");
    }
    protected void Button6_Click(object sender, EventArgs e)
    {
        if (!base.admin.CheckAdminPower(15))
        {
            base.WriteLog("Check", Language.GetAdminMsg("Log/Access", "0"), "Ads");
            base.WriteRightErrMsg();
        }
        string text = "";
        foreach (GridViewRow gridViewRow in this.GridView1.Rows)
        {
            CheckBox checkBox = (CheckBox)gridViewRow.FindControl("CheckBox1");
            if (checkBox.Checked)
            {
                text = text + checkBox.Text + ",";
            }
        }
        if (text != "")
        {
            string text2 = text.Remove(text.Length - 1);
            AdZoneBll adZoneBll = new AdZoneBll();
        }
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        if (!base.admin.CheckAdminPower(15))
        {
            base.WriteLog("Check", Language.GetAdminMsg("Log/Access", "0"), "Ads");
            base.WriteRightErrMsg();
        }
        string text = "";
        foreach (GridViewRow gridViewRow in this.GridView1.Rows)
        {
            CheckBox checkBox = (CheckBox)gridViewRow.FindControl("CheckBox1");
            if (checkBox.Checked)
            {
                text = text + checkBox.Text + ",";
            }
        }
        if (text != "")
        {
            string adZoneActive = text.Remove(text.Length - 1);
            AdZoneBll adZoneBll = new AdZoneBll();
            adZoneBll.SetAdZoneActive(adZoneActive);
        }
    }
    protected void Button7_Click(object sender, EventArgs e)
    {
        if (!base.admin.CheckAdminPower(15))
        {
            base.WriteLog("Check", Language.GetAdminMsg("Log/Access", "0"), "Ads");
            base.WriteRightErrMsg();
        }
        string text = "";
        foreach (GridViewRow gridViewRow in this.GridView1.Rows)
        {
            CheckBox checkBox = (CheckBox)gridViewRow.FindControl("CheckBox1");
            if (checkBox.Checked)
            {
                text = text + checkBox.Text + ",";
            }
        }
        if (text != "")
        {
            string adZoneUnActive = text.Remove(text.Length - 1);
            AdZoneBll adZoneBll = new AdZoneBll();
            adZoneBll.SetAdZoneUnActive(adZoneUnActive);
        }
    }
    protected void GridView1_DataBound(object sender, EventArgs e)
    {
        bool flag = base.admin.CheckAdminPower(14);
        bool flag2 = base.admin.CheckAdminPower(13);
        foreach (GridViewRow gridViewRow in this.GridView1.Rows)
        {
            if (gridViewRow.Cells[7].Text.ToLower() == "false")
            {
                gridViewRow.Cells[7].Text = "否";
            }
            else
            {
                gridViewRow.Cells[7].Text = "是";
            }
            string text = gridViewRow.Cells[3].Text.Trim();
            if (text == null)
            {
                goto IL_231;
            }
            //TODO 刘林注释，这部分代码需要看下原理，重新实现
            //if (<PrivateImplementationDetails>{D307E7D9-7B82-4182-B0ED-028A02C8E8FC}.$$method0x6000061-1 == null)
            //{
            //    <PrivateImplementationDetails>{D307E7D9-7B82-4182-B0ED-028A02C8E8FC}.$$method0x6000061-1 = new Dictionary<string, int>(7)
            //    {

            //        {
            //            "1",
            //            0
            //        },

            //        {
            //            "2",
            //            1
            //        },

            //        {
            //            "3",
            //            2
            //        },

            //        {
            //            "4",
            //            3
            //        },

            //        {
            //            "5",
            //            4
            //        },

            //        {
            //            "6",
            //            5
            //        },

            //        {
            //            "7",
            //            6
            //        }
            //    };
            //}
            int num;
            //TODO 刘林注释，这部分代码需要看下原理，重新实现
            num = 0;
            //if (!<PrivateImplementationDetails>{D307E7D9-7B82-4182-B0ED-028A02C8E8FC}.$$method0x6000061-1.TryGetValue(text, out num))
            //{
            //    goto IL_231;
            //}
            switch (num)
            {
                case 0:
                    gridViewRow.Cells[3].Text = " 矩形横幅";
                    break;
                case 1:
                    gridViewRow.Cells[3].Text = " 弹出窗口";
                    break;
                case 2:
                    gridViewRow.Cells[3].Text = " 随屏移动";
                    break;
                case 3:
                    gridViewRow.Cells[3].Text = " 固定位置";
                    break;
                case 4:
                    gridViewRow.Cells[3].Text = " 漂浮移动";
                    break;
                case 5:
                    gridViewRow.Cells[3].Text = " 文字代码";
                    break;
                case 6:
                    gridViewRow.Cells[3].Text = " 下拉式";
                    break;
                default:
                    goto IL_231;
            }
        IL_24D:
            text = gridViewRow.Cells[4].Text.Trim();
            if (text == null)
            {
                goto IL_2F8;
            }
            if (!(text == "1"))
            {
                if (!(text == "2"))
                {
                    if (!(text == "3"))
                    {
                        goto IL_2F8;
                    }
                    gridViewRow.Cells[4].Text = "按顺序循环显示";
                }
                else
                {
                    gridViewRow.Cells[4].Text = " 按权重优先显示";
                }
            }
            else
            {
                gridViewRow.Cells[4].Text = "按权重随机显示";
            }
        IL_314:
            if (!flag)
            {
                ((LinkButton)gridViewRow.Cells[8].FindControl("cl")).Visible = false;
            }
            if (!flag2)
            {
                gridViewRow.Cells[8].Controls[1].Visible = false;
            }
            continue;
        IL_2F8:
            gridViewRow.Cells[4].Text = "没有此显示方式";
            goto IL_314;
        IL_231:
            gridViewRow.Cells[3].Text = "类型出错";
            goto IL_24D;
        }
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
        e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
    }
}
